<template>
	<view class="min-vh-100 flex-col  w-100" style="background-color: #F3F3F3;">
		<view class="  brs-12 mt-12  hh position-relative">
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" bar-width="100" active-color="#D85886" ></u-tabs>
			<view class="d-flex flex-column px-3 reserva">
				<template v-if="listShow.length">
					<view class="card h-100  pt-12" v-for="(v,i) in listShow" :key="i">
						<view class="d-flex justify-content-between card-top px-3 py-2 ">
							<view class="font-500 ellipsis-line w-0 flex-1">
								消费总计<text class="ps-2 font-600">{{v.price}}</text><text
									class="font-400 font-12 text-666D73 ps-1">元</text>
							</view>
							<view class="font-bold " v-if="!current">
								<text class="font-bold text-ccc" v-show="!v.type">未完成</text>
								<text class="font-bold text-ccc" v-show="v.type==1">已完成</text>
								<text class="font-bold text-ccc" v-show="v.type==2">已取消</text>
							</view>
							<view class="font-bold text-ccc" v-else-if="current==1">未完成</view>
							<view class=" font-bold text-ccc" v-else-if="current==2">已完成</view>
							<view class="font-bold text-ccc" v-else-if="current==3">已取消</view>
						</view>
						<view class="bg-white d-flex content p-3">
							<view class="pic">
								<image class="w-100 h-100 brs-4" :src="v.store_bannerimage" mode="aspectFill">
								</image>
							</view>
							<view class="detail ps-12 flex-1">
								<view class="font-600 pb-1">{{v.store_name}}</view>
								<view class="font-500 pb-12">{{v.room_name}}</view>
								<view class="d-flex font-12 font-500 text-AAB5BF ">
									<view class="">使用时间：</view>
									<view class="">
										{{v.startime|setTime('YYYY/MM/DD HH:mm')}}-{{v.endtime |setTime('HH:mm')}}
									</view>
								</view>
								<view class="d-flex font-12 font-500 text-AAB5BF pt-1">
									<view class="">下单时间：</view>
									<view class="">{{v.createtime*1000|setTime('YYYY/MM/DD HH:mm')}}</view>
								</view>
								<view class="d-flex font-12 font-500 text-AAB5BF ellipsis-line pt-1 ">
									<view class="">支付方式：</view>
									<view class=" text-theme d-flex flex-1 justify-content-between" v-if="v.pay_way==1"
										@click="toMyVoucherDetail(v.card_id)">
										<view class="ellipsis-line w-0 flex-1">{{v.card_name}}</view>
										<u-icon name="arrow-right"></u-icon>
									</view>
									<view class="" v-else>{{['卡券支付','余额支付','微信支付 ','其他支付'][v.pay_way-1]}}</view>
								</view>
								<view class="d-flex font-12 font-500 text-AAB5BF pt-1">
									<view class="">订单编号：</view>
									<view class="">
										<text>{{v.order_num}}</text><text class="text-theme ps-2"
											@click="copy(v.order_num)">复制</text>
									</view>
								</view>
							</view>
						</view>
					</view>
				</template>
				<view v-else class="empty d-flex justify-content-center flex-column align-items-center h-100">
					<image src="../../static/imgs/empty.png" class="img" />
					<view class="text-AAB5BF mt-1 pt-3">暂时没有数据</view>
				</view>
			</view>


		</view>

	</view>
</template>

<script>
	import config from '@/config.js';
	import monent from 'moment'
	export default {
		data() {
			return {
				list: [{
					name: '全部订单'
				}, {
					name: '未完成'
				}, {
					name: '已完成',
				}, {
					name: '已取消',
				}],
				current: 0,
				listAll: [],
				listShow: []
			};
		},
		onLoad() {
			uni.hideShareMenu()
			// this.$u.api.getUserInfo()
			// 	.then(res => {
			// 		this.model = Object.assign(this.model, res.data) // 合并code, 要不后面错误
			// 	})
			this.getReservation()
		},
		computed: {
			// whichlist() {
			// 	return ['listAll','list1','list2','list3'][this.current]
			// }
		},
		methods: {
			getReservation() {
				this.$u.api.getUserAllReservation().then((res) => {
					// console.log(res);
					this.listShow = this.listAll = res.data.map(e => {
						return {
							...e,
							type: e.re_status == '2' ? 2 : e.re_status == '1' && monent(e.endtime).valueOf() >
								Date.now() ? 0 : 1
						}
					})

				})
			},
			change(index) {
				this.current = index;
				this.listShow = []
				if (!index) return this.listShow = this.listAll
				this.listShow = this.listAll.filter((e) => {
					if (index == 3 && e.re_status == '2') {
						return e
					}
					if (index == 1 && e.re_status == '1' && monent(e.endtime).valueOf() > Date.now()) {
						return e
					}
					//已完成
					// && Date.now() >
					// 	monent(e.startime).valueOf()
					if (index == 2 && e.re_status == '1' && Date.now() > monent(e.endtime).valueOf()) {
						return e
					}
				})
			},
			toMyVoucherDetail(id) {
				this.$u.route({
					url: 'pages/myCenter/myVoucherDetail',
					params: {
						id: id
					}
				})
			}
		}
	};
</script>

<style scoped lang="scss">
	.reserva {
		>view:last-child {
			padding-bottom: 40rpx;
		}
	}
	
	.text-ccc {
		color: #373737;
	}

	.card {
		&-top {
			background-color: #F692B6;
			border-radius: 12px 12px 0 0;
		}

		.content {
			border-radius: 0 0 12px 12px;

			.pic {
				width: 146rpx;
				height: 272rpx;
			}

		}
	}

	.empty {
		padding-top: calc(30vh - 244rpx);

		image {
			width: 288rpx;
			height: 304rpx;
		}
	}
</style>